Skip to content

[FSSDK-13300] Remove dead Python 3.7 typing guards - #526

Merged
Farhan Anjum (FarhanAnjum-opti) merged 2 commits into
masterfrom
farhan-anjum/FSSDK-13300-remove-py37-typing-guards
Oct 26, 2026
Merged

Farhan Anjum (FarhanAnjum-opti) merged 2 commits into
masterfrom
farhan-anjum/FSSDK-13300-remove-py37-typing-guards

Conversation

@FarhanAnjum-opti

@FarhanAnjum-opti Farhan Anjum (FarhanAnjum-opti) commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace every if version_info < (3, 8): from typing_extensions import ... else: from typing import ... block (20 modules) with a direct typing import of Final, Literal, Protocol or TypedDict, and drop the now-unused from sys import version_info imports
  • Remove the [mypy-optimizely.helpers.types] no_warn_unused_ignores override in mypy.ini. It only existed for the # type: ignore on the old conditional TypedDict import, which is gone.

Why: type-check (3.11) and type-check (3.12) have failed on every PR and on master since mypy 2.4.0 was released (2026-10-01 20:39 UTC; the last green run was at 20:10 UTC). mypy 2.4.0 treats typing.Protocol and typing_extensions.Protocol as different types, so it flags the conditional import as an incompatible redefinition:

optimizely/event_dispatcher.py:29: error: Incompatible import of "Protocol"  [assignment]
optimizely/odp/lru_cache.py:25: error: Incompatible import of "Protocol"  [assignment]

The < (3, 8) branches only run on Python 3.7, which hasn't been supported since 5.0 (README: "Version 5.0+: Python 3.8+"), so this removes dead code and changes no runtime behavior on any supported version. requirements/typing.txt is unchanged, so mypy stays unpinned as on master.

Not in this PR: the version_info < (3, 10) TypeGuard guard in event/event_id_normalizer.py is still needed while 3.9 is supported. Raising the minimum Python version is tracked separately in FSSDK-13301.

Test plan

  • Before the change, on master: mypy 2.3.1 passes and mypy 2.4.0 fails with the 2 errors above
  • With this change, mypy 2.4.0 (installed unpinned from requirements/typing.txt) on Python 3.11 and 3.12 passes both CI commands:
    • mypy . --exclude "tests/testapp": Success: no issues found in 97 source files
    • mypy . --exclude "tests/" --strict: Success: no issues found in 57 source files. This also confirms the removed mypy.ini override isn't needed.
  • pytest --cov=optimizely on Python 3.9, 3.11 and 3.12: 1036 passed on each
  • ruff check .: all checks passed

Issues

🤖 Generated with Claude Code

mypy 2.4.0 rejects the `if version_info < (3, 8)` conditional Protocol
imports, failing type-check on every PR. Those branches only run on
Python 3.7, which has been unsupported since 5.0, so import Final,
Literal, Protocol and TypedDict directly from typing. Drop the mypy.ini
unused-ignore override that existed only for the old TypedDict import,
and pin mypy~=2.4.0 so new mypy releases can't break CI unannounced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep requirements/typing.txt as on master. The typing import cleanup
alone fixes the mypy 2.4.0 failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@FarhanAnjum-opti Farhan Anjum (FarhanAnjum-opti) changed the title [FSSDK-13300] Remove dead Python 3.7 typing guards and pin mypy [FSSDK-13300] Remove dead Python 3.7 typing guards Oct 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, mechanical cleanup. The < (3, 8) branches are dead for the supported 3.8+ range, and the remaining TypeGuard guard for 3.9 is correctly left alone. Moving the TYPE_CHECKING block in user_profile.py out of the old else branch keeps the same behavior. LGTM.

@FarhanAnjum-opti
Farhan Anjum (FarhanAnjum-opti) merged commit eff999b into master Oct 26, 2026
17 of 18 checks passed
@FarhanAnjum-opti
Farhan Anjum (FarhanAnjum-opti) deleted the farhan-anjum/FSSDK-13300-remove-py37-typing-guards branch October 26, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants